package ${package.Controller};

import org.springframework.web.bind.annotation.RequestMapping;
import ${package.Service}.${table.serviceName};
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>
<#if swagger2>
import io.swagger.annotations.*;
import springfox.documentation.annotations.ApiIgnore;
</#if>
import org.springframework.web.bind.annotation.*;
import ${cfg.respClassImport};
import ${cfg.pageRespImport};
import ${cfg.respPackage}.${entity}VO;
import ${cfg.reqPackage}.${entity}QryReq;
import ${cfg.reqPackage}.${entity}AddReq;
import ${cfg.reqPackage}.${entity}UpdateReq;
import lombok.AllArgsConstructor;

import java.util.List;

/**
 * ${table.comment!} 前端控制器
 * @author ${author}
 * @since ${date}
 */
<#if swagger2>
@Api(tags = {"${table.comment}-管理"})
</#if>
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
 <#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
 <#else>
@AllArgsConstructor
public class ${table.controllerName} {
 </#if>

    private final ${table.serviceName} ${cfg.classname}Service;

    /**
     * ${table.comment}查询-分页
     */
    @GetMapping("page")
    @ApiOperation(value = "${table.comment}查询-分页", notes = "${table.comment}查询-分页")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "current", value = "当前的页数", defaultValue = "1"),
        @ApiImplicitParam(name = "size", value = "当前分页的条数", defaultValue = "10")
    })
    public ${cfg.respClass}<${cfg.pageClass}<${entity}VO>> page(@ApiIgnore Page page,${entity}QryReq req) {
      return ${cfg.respSucc}(${cfg.classname}Service.pageExt(page,req));
    }

    /**
     * ${table.comment}查询-非分页
     */
    @GetMapping("")
    @ApiOperation(value = "${table.comment}查询-非分页", notes = "${table.comment}查询-非分页")
    public ${cfg.respClass}<List<${entity}VO>> list(${entity}QryReq req) {
      return ${cfg.respSucc}(${cfg.classname}Service.listExt(req));
    }

    /**
     * 通过id查询${table.comment}
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "通过id查询${table.comment}", notes = "通过id查询${table.comment}")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "主键id", required = true)
    })
    public ${cfg.respClass}<${entity}VO> getById(@PathVariable("id") String id){
        return ${cfg.respSucc}(${cfg.classname}Service.getByIdExt(id));
    }

    /**
     * 新增${table.comment}
     */
    @PostMapping
    @ApiOperation(value = "新增${table.comment}", notes = "新增${table.comment}")
    public ${cfg.respClass}<Boolean> save(@RequestBody ${entity}AddReq req){
        return ${cfg.respSucc}(${cfg.classname}Service.saveExt(req));
    }

    /**
     * 修改${table.comment}
     */
    @PutMapping("")
    @ApiOperation(value = "修改${table.comment}", notes = "修改${table.comment}")
    public ${cfg.respClass}<Boolean> updateById(@RequestBody ${entity}UpdateReq req){
        return ${cfg.respSucc}(${cfg.classname}Service.updateByIdExt(req));
    }

    /**
     * 通过id删除${table.comment}
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除${table.comment}", notes = "删除${table.comment}")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "主键id", required = true)
    })
    public ${cfg.respClass}<Boolean> delete(@PathVariable String id){
        return ${cfg.respSucc}(${cfg.classname}Service.removeById(id));
    }
}

